
/* The path from trade to right-wing populism in Europe.
   Electoral Studies 60 (2019)
   Hays, Lim, Spoon
   
   Replication code for the main manuscript
   
   stata version: 15
   packages: mediation (if not installed yet, run "ssc install mediation")

*/


use "./final_replication.dta", clear


// Covariates 

global individual female age edu1-edu6 unemployed relig union_mem hinctnta

global regional reg_unemp_rate_lag1 reg_growth_rate for_born_diff 

// NUTS1/Country fixed effects 

global cntryfe c3 c6

global nutfe  n1 n2 n3 n4 n5 n22 n23 n24 n25 n26 n29 n30 n31 n33 n34 n35 n36 n37 n38 n39 n40 n41 n42 n43 n44



//Table 1. Import shocks and electoral support for the radical right. 

foreach x of varlist imm_cult imm_bgeco socio egocentric {
  
 reg `x' ie1000 female age edu1-edu6 $cntryfe $nutfe, cluster(coun_region)
  
}

logit vote_right2 ie1000 female age edu1-edu6 $cntryfe $nutfe, cluster(coun_region)


//Table 2. Import shocks and electoral support for the radical right (with additional control variable)

foreach x of varlist imm_cult imm_bgeco socio egocentric {
  
 reg `x' ie1000 $individual $regional $cntryfe $nutfe, cluster(coun_region)
 
 
}

logit vote_right2 ie1000 $individual $regional $cntryfe $nutfe, cluster(coun_region)

//Table 3 (Mediation Analysis)

//Import shock percentile 
pctile pct5 = ie1000 if vote_right2 !=., nq(20)

return list

//80, 85, 90, 95 percentile 
scalar percentile75 = r(r15)
scalar percentile80 = r(r16)
scalar percentile85 = r(r17)
scalar percentile90 = r(r18)
scalar percentile95 = r(r19)

//Table 3. Mediated effects of import shocks on electoral support for the radical right


medeff (regress imm_cult ie1000  $individual $regional $nutfe $cntryfe) ///
 (logit vote_right2 ie1000   imm_cult $individual $regional $nutfe $cntryfe) ///
,mediate(imm_cult) treat(ie1000 0  `=percentile90') sims(1000) vce(cluster coun_region)

medsens (regress imm_cult ie1000  $individual $regional $nutfe $cntryfe) ///
 (logit vote_right2 ie1000 imm_cult $individual $regional $nutfe $cntryfe) ///
,mediate(imm_cult) treat(ie1000) 

medeff (regress imm_bgeco ie1000  $individual $regional $nutfe $cntryfe) ///
 (logit vote_right2 ie1000 imm_bgeco  $individual $regional $nutfe $cntryfe) ///
,mediate(imm_bgeco) treat(ie1000 0  `=percentile90') sims(1000) vce(cluster coun_region)

medsens (regress imm_bgeco ie1000  $individual $regional $nutfe $cntryfe) ///
 (logit vote_right2 ie1000  imm_bgeco $individual $regional $nutfe $cntryfe) ///
,mediate(imm_bgeco) treat(ie1000) 

medeff (regress socio ie1000  $individual $regional $nutfe $cntryfe) ///
 (logit vote_right2 ie1000 socio  $individual $regional $nutfe $cntryfe) ///
,mediate(socio) treat(ie1000 0  `=percentile90') sims(1000) vce(cluster coun_region)

medsens (regress socio ie1000  $individual $regional $nutfe $cntryfe) ///
 (logit vote_right2 ie1000 socio  $individual $regional $nutfe $cntryfe) ///
,mediate(socio) treat(ie1000) 

medeff (regress egocentric ie1000 $individual $regional $nutfe $cntryfe) ///
 (logit vote_right2 ie1000 egocentric  $individual $regional $nutfe $cntryfe) ///
,mediate(egocentric) treat(ie1000 0  `=percentile90') sims(1000) vce(cluster coun_region)

medsens (regress egocentric ie1000 $individual $regional $nutfe $cntryfe) ///
 (logit vote_right2 ie1000 egocentric $individual $regional $nutfe $cntryfe) ///
,mediate(egocentric) treat(ie1000) 

